window.addEventListener("load", function () {
	// 功能一:实现表单验证
	//获取相关节点
	console.log($("#userName"), $("#phoneNumber"), $("#passWord"), $("#reg"));
	//给立即注册绑定点击事件
	$("#reg").addEventListener("click", function () {
		//点击后判断输入框的文本长度,不满足则弹出红色提示相关
		let psdValue = $("#passWord").value;
		let usnValue = $("#userName").value;
		let pnmValue = $("#phoneNumber").value;
		console.log($("#passWord").nextElementSibling);
		// console.log($("#passWord").value.length);
		if (psdValue.length < 6 || psdValue.length > 12) {
			$("#passWord").style.border = "1px solid red";
			$("#passWord").nextElementSibling.textContent = "请输入6至12位的密码";
			$("#passWord").nextElementSibling.style.color = "red";
		} else {
			$("#passWord").style.border = "1px solid black";
			$("#passWord").nextElementSibling.textContent = "";
		}
		if (usnValue.length < 6 || usnValue.length > 20) {
			$("#userName").style.border = "1px solid red";
			$("#userName").nextElementSibling.textContent = "请输入6至20位的字母数字";
			$("#userName").nextElementSibling.style.color = "red";
		} else {
			$("#userName").style.border = "1px solid black";
			$("#userName").nextElementSibling.textContent = "";
		}
		// const regex3 =
		// 	/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
		// pnmValue.length !== 11
		// regex3.test(pnmValue)

		if (pnmValue.length !== 11) {
			$("#phoneNumber").style.border = "1px solid red";
			$("#phoneNumber").nextElementSibling.textContent = "请输入正确的手机号码";
			$("#phoneNumber").nextElementSibling.style.color = "red";
		} else {
			$("#phoneNumber").style.border = "1px solid black";
			$("#phoneNumber").nextElementSibling.textContent = "";
		}
		// 验证码
	});
	// 功能二:设置定时器获取验证码倒计时
	//1.获取相关节点
	//2.给获取验证码按钮绑定点击事件,点击后按钮被禁用
	//3.设置周期定时器,每一秒减一i--
	//4.当i = 0 时,重新恢复按钮状态
	$("#getcomfirm button").addEventListener("click", function () {
		let i = 11;
		const timer = window.setInterval(function () {
			i--;
			$("#getcomfirm button").disabled = true;
			$("#getcomfirm button").textContent = i;
			if (i < 0) {
				window.clearInterval(timer);
				$("#getcomfirm button").disabled = false;
				$("#getcomfirm button").textContent = "获取验证码";
			}
			console.log($("#getcomfirm button").disabled);
		}, 1000);
	});
});
